<template>
  <div>
    <van-nav-bar
      title="我的收藏"
      left-text="返回"
      left-arrow
      @click-left="back()"
    />
    <div class="bg"></div>
    <van-empty
      v-show="nullstyle"
      class="custom-image"
      image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
      description="暂无订单信息"
    />
    <div class="userinfo">
      <div class="hotproduct" v-for="(item, index) in proData" :key="index">
        <div class="productimg">
          <img
            :src="item.smallImg"
            alt=""
            width="100px"
            height="100px"
            @click="viewDetail(item.pid, item.type)"
          />
        </div>
        <div class="producttext">
          <div class="pdname">{{ item.name }}</div>
          <div class="pdenname">{{ item.enname }}</div>
          <div class="pdprice">
            ￥{{ item.price }}
            <van-icon name="delete-o" size="16px" @click="notlike(item.pid)" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Alllike",
  data() {
    return {
      nullstyle: false,
      appkey: "U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
      tokenString: this.$cookies.get("TOKEN"),
      proData: [],
    };
  },
  created() {
    this.findAllLike();
  },
  methods: {
    //点击跳转商品详情
    viewDetail(pid, type) {
      this.$router.push({ name: "Detail", query: { pid, type } });
    },
    //返回我的页面
    back() {
      this.$router.push({ name: "Mine" });
    },
    //删除收藏商品
    notlike(e) {
      let str = `appkey=${this.appkey}&pid=${e}&tokenString=${this.tokenString}`;
      this.axios({
        method: "post",
        url: "/notlike",
        data: str,
      }).then((res) => {
        console.log(res);
        this.findAllLike();
      });
    },
    //查找全部收藏商品
    findAllLike() {
      this.axios({
        method: "get",
        url: "findAllLike",
        params: {
          appkey: this.appkey,
          tokenString: this.tokenString,
        },
      }).then((res) => {
        this.proData = res.data.result;
        if (res.data.result.length == 0) {
          this.nullstyle=true
        }else{
            this.nullstyle=false
        }
        console.log(res);
      });
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.van-icon-delete-o:before {
  margin-left: 40px;
}
.producttext {
  // text-align: center;
  margin-top: -5px;
  margin-left: 10px;
  .pdname {
    font-size: 14px;
  }
  .pdenname {
    font-size: 12px;
    margin-top: 3px;
    color: #b39b9d;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .pdprice {
    font-weight: bold;
    color: #0c34ba;
    margin-top: 10px;
  }
}
.productimg {
  position: relative;
  // margin-top: 10px;
  // display: flex;
  margin: 10px;
}
.hotproduct {
  width: 33%;
  height: auto;
  //   background-color: #fff;
  //   margin-left: 2%;
  //   margin-bottom: 10px;
}
.bg {
  height: 150px;
  background-color: blue;
}
.userinfo {
  display: flex;
  flex-wrap: wrap;
  margin: 0 10px;
  // opacity:0.5;
  //   background: rgba(255, 255, 255, 0.5);
  background-color: #fff;
  height: auto;
  transform: translateY(-50px);
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
</style>